/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.util;

import java.util.ArrayList;
import java.util.List;

import com.edi.db.EdiDb;
import com.edi.db.type.BigDecimalType;
import com.edi.db.type.BlobType;
import com.edi.db.type.BooleanType;
import com.edi.db.type.ClobType;
import com.edi.db.type.DateType;
import com.edi.db.type.FloatType;
import com.edi.db.type.IntegerType;
import com.edi.db.type.NullableType;
import com.edi.db.type.StringType;

public class SqlTypeHelper {
	private static List<String> specialTypeList = new ArrayList<String>();

	//	public static NullableType getSqlType(int type){
	//		NullableType rType=EdiDb.STRING;
	//		switch (type){ 
	//		case Types.LONGVARCHAR:
	//			rType=EdiDb.LONG;
	//			break; 
	//		case Types.BINARY:
	//			rType=EdiDb.BINARY;
	//			break;
	//		case Types.BLOB:
	//			rType=EdiDb.BLOB;
	//			break;
	//		case Types.BOOLEAN:
	//			rType=EdiDb.BOOLEAN;
	//			break;
	//		case Types.CHAR:
	//			rType=EdiDb.CHARACTER;
	//			break;
	//		case Types.CLOB:
	//			rType=EdiDb.CLOB;
	//			break;
	//		case Types.DATE:
	//			rType=EdiDb.DATE;
	//			break;
	//		case Types.DECIMAL:
	//			rType=EdiDb.BIG_DECIMAL;
	//			break;
	//		case Types.DOUBLE:
	//			rType=EdiDb.DOUBLE;
	//			break;
	//		case Types.FLOAT:
	//			rType=EdiDb.FLOAT;
	//			break;
	//		case Types.INTEGER:
	//			rType=EdiDb.INTEGER;
	//			break;
	//		case Types.TIME:
	//			rType=EdiDb.TIME;
	//			break;
	//		case Types.TIMESTAMP:
	//			rType=EdiDb.TIMESTAMP;
	//			break;
	//		case Types.VARCHAR:
	//			rType=EdiDb.STRING;
	//			break;
	//		case Types.VARBINARY:
	//			rType=EdiDb.BINARY;  
	//			break;
	//		case Types.NUMERIC:
	//			rType=EdiDb.BIG_INTEGER;
	//			break; 
	//		case Types.TINYINT:
	//			rType=EdiDb.BOOLEAN;
	//		}
	//		return rType;
	//	}

	public static NullableType getSqlType(String type) {
		if (type.equalsIgnoreCase(EdiDb.TYPE_BOOLEAN))
			return new BooleanType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_STRING))
			return new StringType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_DATE))
			return new DateType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_FLOAT))
			return new FloatType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_IMAGE))
			return new BlobType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_DECIMAL))
			return new BigDecimalType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_CURRENCY))
			return new BigDecimalType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_INT))
			return new IntegerType();

		if (type.equalsIgnoreCase(EdiDb.TYPE_TEXT))
			return new ClobType();

		return new StringType();
	}

	static {
		initSpecialType();
	}

	private static void initSpecialType() {
		specialTypeList.add("text");
		specialTypeList.add("datetime");
		specialTypeList.add("date");
		specialTypeList.add("time");
		specialTypeList.add("timestamp");
		specialTypeList.add("calendar_date");
		specialTypeList.add("calendar");
		specialTypeList.add("blob");
		specialTypeList.add("clob");
		specialTypeList.add("boolean");
	}

	public static List<String> getSpecialTypeList() {
		return specialTypeList;
	}
}
